package com.link2room.rodimus.controller.manager;

import com.link2room.common.constant.DefaultValue;
import com.link2room.common.dto.param.base.BaseL2rParamDto;
import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.sideswipe.permissionResouces.annotation.L2RPermissionResources;
import com.link2room.rodimus.dto.param.base.SignInAwardTypeDto;
import com.link2room.rodimus.dto.param.base.SignInBaseDto;
import com.link2room.rodimus.dto.param.manager.SignInRuleBaseCreateParamDto;
import com.link2room.rodimus.dto.param.manager.SignInRuleBaseFindParamDto;
import com.link2room.rodimus.dto.param.manager.SignInRuleBaseModifyParamDto;
import com.link2room.rodimus.facade.ISignInManagerFacadeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static com.link2room.rodimus.constant.PermissionConstant.*;

/**
 * Created by LN on 2018/1/4
 */
@Api(tags = "签到相关")
@RestController
@RequestMapping("/manager/SignInRules")
public class SignInManagerController {

    @Resource
    private ISignInManagerFacadeService signInManagerFacadeService;

    @RequestMapping(method = RequestMethod.POST)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "signInRuleBaseCreateParamDto", value = "signInRuleBaseCreateParamDto", required = true, paramType = "body"),
    })
    @L2RPermissionResources(value = createSignInRuleBase, name = "签到活动创建")
    public BaseResultDto createSignInRuleBase(
            @RequestBody SignInRuleBaseCreateParamDto signInRuleBaseCreateParamDto
            ) throws Exception {
        signInManagerFacadeService.createSignInRuleBase(signInRuleBaseCreateParamDto);
        BaseResultDto res = new BaseResultDto();
        res.setResultCode(0);
        return res;
    }

    @RequestMapping(method = RequestMethod.GET)
    @ApiOperation(value = "签到规则列表",response = SignInBaseDto.class)
    @ApiImplicitParams(value = {
    })
    @L2RPermissionResources(value = getSignInRuleBases, name = "签到规则列表")
    public BaseResultDto<SignInBaseDto> getSignInRuleBases(
    ) throws Exception {
        BaseResultDto res = new BaseResultDto();
        res.setResultCode(0);
        res.setQueryResult(signInManagerFacadeService.getSignInBases(new SignInRuleBaseFindParamDto()));
        return res;
    }
    @RequestMapping(value = "/{ruleBaseCode}",method = RequestMethod.GET)
    @ApiOperation(value = "签到规则详情",response = SignInBaseDto.class)
    @L2RPermissionResources(value = getSignInRuleBase, name = "签到规则详情")
    public BaseResultDto<SignInBaseDto> getSignInRuleBase(
            @PathVariable("ruleBaseCode") String ruleBaseCode
    ) throws Exception {
        SignInRuleBaseFindParamDto paramDto = new SignInRuleBaseFindParamDto();
        paramDto.setCode(ruleBaseCode);
        BaseResultDto res = new BaseResultDto();
        res.setResultCode(0);
        res.setResultInfo(signInManagerFacadeService.getSignInBase(paramDto));
        return res;
    }

    @RequestMapping(value = "/{ruleBaseCode}",method = RequestMethod.PUT)
    @ApiOperation(value = "签到规则修改")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "ruleBaseCode", value = "ruleBaseCode", required = true, paramType = "path")
    })
    @L2RPermissionResources(value = modifySignInRuleBase, name = "签到规则修改")
    public BaseResultDto<SignInBaseDto> modifySignInRuleBase(
            @PathVariable("ruleBaseCode") String ruleBaseCode,
            @RequestBody SignInRuleBaseModifyParamDto paramDto
    ) throws Exception {
        paramDto.setCode(ruleBaseCode);
        signInManagerFacadeService.modifySignInRuleBase(paramDto);
        BaseResultDto res = new BaseResultDto();
        res.setResultCode(0);
        return res;
    }

    @RequestMapping(value = "/isDuplicate",method = RequestMethod.GET)
    @ApiOperation(value = "规则代码是否重复")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "ruleCode", value = "ruleCode", required = true, paramType = "query")
    })
    public BaseResultDto isDuplicate(
            @RequestParam(name = "ruleCode") String ruleCode
    ) throws Exception {
        SignInRuleBaseFindParamDto paramDto = new SignInRuleBaseFindParamDto();
        paramDto.setCode(ruleCode);
        BaseResultDto res = new BaseResultDto();
        res.setResultCode(0);
        res.setResultInfo(signInManagerFacadeService.ruleCodeIsDuplicate(paramDto) ? DefaultValue.T : DefaultValue.F);
        return res;
    }

    @RequestMapping(value = "/awardTypes",method = RequestMethod.GET)
    @ApiOperation(value = "奖励类型")
    @ApiImplicitParams(value = {
    })
    public BaseResultDto<SignInAwardTypeDto> awardTypes(

    ) throws Exception {

        BaseResultDto res = new BaseResultDto();
        res.setResultCode(0);
        res.setQueryResult(signInManagerFacadeService.awardTypes(new BaseL2rParamDto()));
        return res;
    }



}
